home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / pmdev / e / demos / pulldownmenu.e < prev    next >
Encoding:
Text File  |  2000-02-28  |  9.0 KB  |  228 lines

  1. /* -- ----------------------------------------------------------------- -- *
  2.  * -- Program.....: PullDownMenu.e                                      -- *
  3.  * -- Author......: Daniel Kasmeroglu <raptor@cs.tu-berlin.de>          -- *
  4.  * -- Description.: Port of an example by Henrik Isaksson.              -- *
  5.  * -- ----------------------------------------------------------------- -- *
  6.  * -- Original header:                                                  -- *
  7.  * --                                                                   -- *
  8.  * --   $VER: PullDownMenu.c 2.1 (05.09.98)                             -- *
  9.  * --                                                                   -- *
  10.  * --   Popup Menu example program                                      -- *
  11.  * --                                                                   -- *
  12.  * --   ©1996-1997 Henrik Isaksson                                      -- *
  13.  * --   All Rights Reserved.                                            -- *
  14.  * --                                                                   -- *
  15.  * --   Run and click the mouse in the window!                          -- *
  16.  * --                                                                   -- *
  17.  * -- ----------------------------------------------------------------- -- */
  18.  
  19. /* -- ----------------------------------------------------------------- -- *
  20.  * --                              Options                              -- *
  21.  * -- ----------------------------------------------------------------- -- */
  22.  
  23. OPT PREPROCESS       -> enable preprocessor
  24.  
  25.  
  26. /* -- ----------------------------------------------------------------- -- *
  27.  * --                              Modules                              -- *
  28.  * -- ----------------------------------------------------------------- -- */
  29.  
  30. MODULE 'libraries/popupmenu' ,
  31.        'intuition/intuition' ,
  32.        'tools/inithook'      ,
  33.        'utility/tagitem'     ,
  34.        'utility/hooks'       
  35.  
  36. MODULE 'popupmenu'
  37.  
  38.  
  39. /* -- ----------------------------------------------------------------- -- *
  40.  * --                               Main                                -- *
  41.  * -- ----------------------------------------------------------------- -- */
  42.  
  43. ->»» PROC main
  44. PROC main()
  45. DEF ma_window  : PTR TO window
  46. DEF ma_menu    : PTR TO popupmenu
  47. DEF ma_imsg1   : PTR TO intuimessage
  48. DEF ma_imsg2   : intuimessage
  49. DEF ma_handler : hook
  50. DEF ma_result
  51.  
  52.   ma_result := TRUE
  53.   inithook( ma_handler, {hoo_MenuHandlerFunc}, {ma_result} )
  54.  
  55.   popupmenubase := OpenLibrary( 'popupmenu.library', 9 )
  56.   IF popupmenubase <> NIL
  57.  
  58.     ma_menu := glo_MakeTestMenu()
  59.     IF ma_menu <> NIL
  60.  
  61.       -> Open a little window
  62.       ma_window := OpenWindowTagList( NIL,
  63.       [ WA_IDCMP       , IDCMP_CLOSEWINDOW OR IDCMP_MOUSEBUTTONS OR IDCMP_VANILLAKEY ,
  64.         WA_RMBTRAP     , TRUE             ,
  65.         WA_DRAGBAR     , TRUE             ,
  66.         WA_WIDTH       , 150              ,
  67.         WA_HEIGHT      , 100              ,
  68.         WA_LEFT        , 0                ,
  69.         WA_TOP         , 100              ,
  70.         WA_TITLE       , 'PullDown Menus' ,
  71.         WA_CLOSEGADGET , TRUE             ,
  72.         TAG_END ] )
  73.  
  74.       IF ma_window <> NIL
  75.  
  76.         WHILE ma_result <> FALSE
  77.  
  78.           -> Wait for a message
  79.           WaitPort( ma_window.userport )
  80.  
  81.           WHILE (ma_imsg1 := GetMsg( ma_window.userport )) <> NIL
  82.  
  83.             -> Copy the contents of it
  84.             CopyMem( ma_imsg1, ma_imsg2, SIZEOF intuimessage )
  85.             ReplyMsg( ma_imsg1 )
  86.  
  87.             -> Send the message to pmlib
  88.             Pm_FilterIMsgA( ma_window, ma_menu, ma_imsg1,
  89.             [ PM_AUTOPULLDOWN ,  TRUE       , -> We want the menu to open automatically
  90.               PM_MENUHANDLER  ,  ma_handler , -> Our menuhandler function
  91.               TAG_END ] )
  92.  
  93.             -> See if the user wants to quit
  94.             IF ma_imsg1.class = IDCMP_CLOSEWINDOW THEN ma_result := FALSE
  95.  
  96.           ENDWHILE
  97.  
  98.         ENDWHILE
  99.  
  100.         CloseWindow( ma_window )
  101.  
  102.       ELSE
  103.         PrintF( 'Window error !\n' )
  104.       ENDIF
  105.  
  106.       Pm_FreePopupMenu( ma_menu )
  107.  
  108.     ELSE
  109.       PrintF( 'Menu error !\n' )
  110.     ENDIF
  111.     CloseLibrary( popupmenubase )
  112.  
  113.   ELSE
  114.     PrintF( 'Cannot open "popupmenu.library" v9+ !\n' )
  115.   ENDIF
  116.  
  117. ENDPROC
  118. ->»»>
  119.  
  120.  
  121. /* -- ----------------------------------------------------------------- -- *
  122.  * --                             Functions                             -- *
  123.  * -- ----------------------------------------------------------------- -- */
  124.  
  125. ->»» PROC glo_MakeTestMenu
  126. PROC glo_MakeTestMenu()
  127. DEF mak_menu : PTR TO popupmenu
  128.  
  129.   mak_menu := PMStartMenu,
  130.                 PMItem( 'Workbench' ),
  131.                   PMSimpleSub,
  132.                     PMCheckItem( 'Backdrop?', 1  ), PM_COMMKEY, 'B', PMEnd,
  133.                     PMItem( 'Execute Command...' ), PM_COMMKEY, 'E', PMEnd,
  134.                     PMItem( 'Redraw All'         ), PMEnd,
  135.                     PMItem( 'Update All'         ), PMEnd,
  136.                     PMItem( 'Last Message'       ), PMEnd,
  137.                     PMItem( 'About...'           ), PM_COMMKEY,  '?', PMEnd,
  138.                     PMItem( 'Quit'               ), PM_USERDATA, 5,   PM_COMMKEY, 'Q', PMEnd,
  139.                   PMEnd,
  140.                 End,
  141.                 PMItem( 'Window' ),
  142.                   PMSimpleSub,
  143.                     PMItem( 'New Drawer'      ), PM_COMMKEY,  'N',  PM_DISABLED, TRUE, PMEnd,
  144.                     PMItem( 'Open Parent'     ), PM_DISABLED, TRUE, PMEnd,
  145.                     PMItem( 'Close'           ), PM_COMMKEY,  'K',  PM_DISABLED, TRUE, PMEnd,
  146.                     PMItem( 'Update'          ), PM_DISABLED, TRUE, PMEnd,
  147.                     PMItem( 'Select Contents' ), PM_COMMKEY,  'A',  PMEnd,
  148.                     PMItem( 'Clean Up'        ), PM_COMMKEY,  '.',  PMEnd,
  149.                     PMItem( 'Snapshot'        ),
  150.                       PMSimpleSub,
  151.                         PMItem( 'Window' ), PMEnd,
  152.                         PMItem( 'All'    ), PMEnd,
  153.                       PMEnd,
  154.                     PMEnd,
  155.                     PMItem( 'Show' ),
  156.                       PMSimpleSub,
  157.                         PMCheckItem( 'Only Icons' , 2 ), PM_EXCLUDE, Pm_ExLstA( [ 3, 0 ] ), PM_CHECKED, TRUE, PMEnd,
  158.                         PMCheckItem( 'All Files'  , 3 ), PM_EXCLUDE, Pm_ExLstA( [ 2, 0 ] ), PMEnd,
  159.                       PMEnd,
  160.                       PM_DISABLED, TRUE,
  161.                       -> PM_BuiltInIcon,       PMIMG_SHOW,
  162.                     PMEnd,
  163.                     PMItem( 'View By' ),
  164.                       PMSimpleSub,
  165.                         PMCheckItem( 'Icon', 4 ), PM_EXCLUDE, Pm_ExLstA( [ 5, 6, 7, 0 ] ), PM_CHECKED, TRUE, PMEnd,
  166.                         PMCheckItem( 'Name', 5 ), PM_EXCLUDE, Pm_ExLstA( [ 4, 6, 7, 0 ] ), PMEnd,
  167.                         PMCheckItem( 'Date', 6 ), PM_EXCLUDE, Pm_ExLstA( [ 4, 5, 7, 0 ] ), PMEnd,
  168.                         PMCheckItem( 'Size', 7 ), PM_EXCLUDE, Pm_ExLstA( [ 4, 5, 6, 0 ] ), PMEnd,
  169.                       PMEnd,
  170.                       PM_DISABLED, FALSE,
  171.                     PMEnd,
  172.                   PMEnd,
  173.                 PMEnd,
  174.                 PMItem( 'Icons' ),
  175.                   PMSimpleSub,
  176.                     PMItem( 'Open'           ), PM_COMMKEY, 'O', PMEnd,
  177.                     PMItem( 'Copy'           ), PM_COMMKEY, 'C', PMEnd,
  178.                     PMItem( 'Rename...'      ), PM_COMMKEY, 'R', PMEnd,
  179.                     PMItem( 'Information...' ), PM_COMMKEY, 'I', PMEnd,
  180.                     PMItem( 'Snapshot'       ), PM_COMMKEY, 'S', PMEnd,
  181.                     PMItem( 'UnSnapshot'     ), PM_COMMKEY, 'U', PMEnd,
  182.                     PMItem( 'Leave Out'      ), PM_COMMKEY, 'L', PMEnd,
  183.                     PMItem( 'Put Away'       ), PM_COMMKEY, 'P', PMEnd,
  184.                     PMBar, PMEnd,
  185.                     PMItem( 'Delete...'      ), PM_DISABLED, TRUE, PMEnd,
  186.                     PMItem( 'Format Disk...' ), PMEnd,
  187.                     PMItem( 'Empty Trash'    ), PM_DISABLED, TRUE, PMEnd,
  188.                   PMEnd,
  189.                 PMEnd,
  190.                 PMItem( 'Tools' ),
  191.                   PMSimpleSub,
  192.                     PMItem( 'ResetWB' ), PMEnd,
  193.                   PMEnd,
  194.                 PMEnd,
  195.               PMEnd
  196.  
  197. ENDPROC mak_menu
  198. ->»»>
  199.  
  200.  
  201. /* -- ----------------------------------------------------------------- -- *
  202.  * --                          Hook-Functions                           -- *
  203.  * -- ----------------------------------------------------------------- -- */
  204.  
  205. ->»» HOOK hoo_MenuHandlerFunc
  206. PROC hoo_MenuHandlerFunc( men_hook : PTR TO hook, men_object, men_msg )
  207. DEF men_menu : PTR TO popupmenu
  208.  
  209.   men_menu := men_object
  210.  
  211.   PrintF( '---\n' )
  212.   PrintF( 'Title:    "\s"\n' , men_menu.ppm_Title )
  213.   PrintF( 'UserData: $\h\n'  , men_menu.ppm_UserData )
  214.   PrintF( 'ID:       $\h\n'  , men_menu.ppm_ID )
  215.  
  216.   -> This is one (the fastest) way of finding out if the item is checked or not:
  217.   -> 0x40000000 = CHECKIT
  218.   -> 0x80000000 = CHECKED
  219.   IF (men_menu.ppm_Flags AND $40000000)
  220.     PrintF( 'Checked?  \s\n', IF men_menu.ppm_Flags AND $80000000 THEN 'Yes' ELSE 'No' )
  221.   ENDIF
  222.  
  223.   IF men_menu.ppm_UserData = 5 THEN PutLong( men_hook.data, FALSE )
  224.  
  225. ENDPROC
  226. ->»»>
  227.  
  228.